﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using MQTT.Share.ConfigurationExtension;
using System;
using System.Collections.Generic;
using System.Text;

namespace MQTT.Share.Extension
{
    public static class MQTTExtension
    {

        public static IServiceCollection AddMQTTServer(this IServiceCollection services)
        {
            services.AddSingleton<IConfigurationManager, ConfigurationManager>();
            return services;
        }

        public static IApplicationBuilder UseMQTTServer(this IApplicationBuilder app, IConfiguration Configuration)
        {            
            return app.UseConfigManager(Configuration);
        }

        public static IApplicationBuilder UseConfigManager(this IApplicationBuilder app, IConfiguration Configuration)
        {
            app.ApplicationServices.GetService<IConfigurationManager>().Configuration = Configuration;
            return app;
        }
    }
}
